import groovy.transform.Field

def invokeMethod(String name, args) {
    print "<${name}"
    args.each { arg ->
        if (arg instanceof Map) {
            arg.each {
                print " ${it.key} ='${it.value}' "
            }
        } else if (arg instanceof Closure) {
            print '>'
            arg.delegate = this
            def value = arg.call()
            if (value) {
                print "${value}"
            }
        }
    }

    println "</${name}>"
}

@Field rst="";
def html(Closure... clsr){
    rst+="<html>\n"
    clsr.each {it->it.run()}
    rst+="</html>\n"
}

def head (Closure... clsr){
    rst+="\t<head>\n"
    rst+="\t</head>\n"
}

def body(Closure ...clsr){
    rst+="\t<body>\n"
    clsr.each {it->it.run()}
    rst+="\t</body>\n"
}

def table(Map map,Closure... clsr){
    rst+="\tt<table>\n"

    rst+="\tt</table>\n"
}

html {

    head {
        meta {

        }
    }
    body {
        table (style:'margin:5px;') {
            tr ('class':'trClass', style:'padding:5px;') {
                td {'Cell1'}
                td {'Cell2'}
                td {'Cell3'}
            }
        }
    }
}


println rst;
